package com.qinghe.pro.service.api.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qinghe.pro.entity.api.Api;
import com.qinghe.pro.mapper.api.ApiMapper;
import com.qinghe.pro.service.api.ApiService;
import com.qinghe.utils.Page;

@Service("apiServiceImpl")
public class ApiServiceImpl implements ApiService {

	@Autowired
	private ApiMapper apiMapper;

	@Override
	public Api get(Integer id) {
		return apiMapper.selectById(id);
	}

	@Override
	public void insert(Api api) {
		apiMapper.insertSelective(api);
	}

	@Override
	public void update(Api api) {
		apiMapper.updateByPrimaryKeySelective(api);
	}

	@Override
	public void delete(Integer id) {
		apiMapper.deleteByPrimaryKey(id);
	}

	@Override
	public List<Api> findByPage(Api api, Page page) {
		PageHelper.startPage(page.getPageNum(), page.getNumPerPage()).setOrderBy("create_time desc");
		List<Api> list = apiMapper.selectAll(api);
		PageInfo<Api> p = new PageInfo<Api>(list);
		page.setTotalCount((int) p.getTotal());
		return list;
	}

	@Override
	public Integer countAll() {
		return apiMapper.countAll();
	}

}
